using System;
using System.DHTML;
using Sys;
using Sys.UI;

using JQuerySharp;




static public class DatetimeUtils
{
    /// <summary>
    /// Get Current Date
    /// </summary>
    /// <returns></returns>
    public static DateTime GetCurrentDate()
    {
        DateTime now = new DateTime();
        return now;

    }

    /// <summary>
    /// Get Day Of Week to Current Date
    /// </summary>
    /// <returns></returns>
    public static DateTime GetDayOfWeek()
    {
        DateTime now = new DateTime();
        DateTime firstDayOfWeek = new DateTime(now.GetFullYear(), now.GetMonth(), now.GetDate() - now.GetDay());
        return firstDayOfWeek;
    }

    /// <summary>
    /// Get First Day Of Current Month
    /// </summary>
    /// <returns></returns>
    public static DateTime GetDayOfMonth()
    {
        DateTime now = new DateTime();
        DateTime firstDayOfMonth = new DateTime(now.GetFullYear(), now.GetMonth(), 1);
        return firstDayOfMonth;
    }

    /// <summary>
    /// Plus number of days in current Date
    /// </summary>
    /// <param name="days"></param>
    /// <returns></returns>
    public static DateTime AddDate(int days)
    {
        DateTime today = new DateTime();
        DateTime DateAdd = new DateTime();
        DateAdd.SetDate(today.GetDay() + days);
        return DateAdd;
    }

    /// <summary>
    /// Subtraction the number of days in current Date
    /// </summary>
    /// <param name="days"></param>
    /// <returns></returns>
    public static DateTime SubDate(int days)
    {
        DateTime today = new DateTime();
        DateTime subtractionDate = new DateTime();
        subtractionDate.SetDate(today.GetDay() - days);
        return subtractionDate;
    }

    /// <summary>
    /// Compare date1 and date2
    ///</summary>
    /// <param name="dt1"></param>
    /// <param name="dt2"></param>
    /// <returns>
    ///     0 whether date1 is equal date2
    ///     1 whether date1 is greater than date2
    ///     -1 whether date1 is less than date2
    ///     -2 whether date is execption
    /// </returns>    
    public static int CompareDate(DateTime date1, DateTime date2)
    {
        int valueCompare = -2;
        try
        {
            if (date1 == date2)
            {
                valueCompare = 0;
            }
            else if (date1 > date2)
            {
                valueCompare = 1;
            }
            else
            {
                valueCompare = -1;
            }
        }
        catch (Exception)
        {}

        return valueCompare;
    }



}
